home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / B-C / Color Window Demo / Open Color Window.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-30  |  2.4 KB  |  67 lines  |  [TEXT/KAHL]

  1. #include "my color.h"
  2.  
  3.  
  4. OpenWindow()    /* Open a new window */
  5. {
  6.     char    wNameDef[256];            /* to hold our default window title */
  7.     char    nextWTitle[256];        /* title of next window to be opened*/
  8.     char    *wName;                 
  9.      
  10.     NumToString (nextWNum, nextWTitle);          /* prepare number for title -- returns C string */
  11.     PtoCstr(nextWTitle);                    /* convert to 'C' type string    */
  12.     strcpy((char *)wNameDef,WindName);        /* WindName is a #define */
  13.     wName = (char *)strcat((char *)wNameDef,(char *)nextWTitle);
  14.     CtoPstr(wNameDef);                        /* convert to 'PASCAL' type string    */
  15.  
  16.     myWindow = (CWindowPtr)NewCWindow (nil, &nextWRect, wNameDef, true, documentProc,
  17.             (CWindowPtr)-1, true, 0);
  18.     SetPort (myWindow);                /*make it the current port*/
  19.     add_scroll_bars(myWindow);    /* create some scroll bars for the new window */
  20.     set_color(myWindow);        /* set the window's color to something hideous */
  21.         
  22.     txRect = thePort->portRect;
  23.     txRect.right = txRect.right - BAR_WIDTH;    /* make the text display rectangle allow for the scroll bars */
  24.     txRect.bottom = txRect.bottom - BAR_WIDTH;
  25.     InsetRect (&txRect, 4, 0);
  26.     textH = TENew (&txRect, &txRect);
  27.     myWinPeek = (CWindowPeek)myWindow;
  28.     myWinPeek->refCon = (long)textH;    /*keep TEHandle in the window's refCon field!*/
  29.     OffsetRect (&nextWRect, windDX, windDY);/*move window down and right*/
  30.     if (nextWRect.right > dragRect.right)        /*move back if it's too far over*/
  31.         OffsetRect (&nextWRect, -nextWRect.left + leftEdge, 0);
  32.     if (nextWRect.bottom > dragRect.bottom)
  33.         OffsetRect (&nextWRect, 0, -nextWRect.top + topEdge);
  34.     nextWNum++;        /*bump number for next window*/
  35.     menusOK = false;
  36.     EnableItem (myMenus [editM],0); /*in case this is the only window*/
  37. }  /* OpenWindow */
  38.  
  39.  
  40. KillWindow(theWindow)    /*Close a window and throw everything away*/
  41.  
  42. CWindowPtr        theWindow;
  43.  
  44. {
  45.     TEDispose (((CWindowPeek)theWindow)->refCon);
  46.                                                             /*throw away TERecord*/
  47.     DisposeWindow (theWindow);    /*throw away WindowRecord*/
  48.     textH = nil;                                /*for TEIdle in main event loop*/
  49.     if (FrontWindow() == nil)                /*if no more windows, disable Close*/
  50.         {        
  51.             DisableItem (myMenus[fileM], closeItem);
  52.             SetCursor(&arrow);
  53.         }
  54.     else /* FrontWindow() != nil */
  55.     {
  56.       if (((CWindowPeek)FrontWindow())->windowKind < 0)
  57.             /*if a desk acc is coming up, enable undo*/
  58.         {
  59.             EnableItem (myMenus[editM], undoItem);
  60.             SetCursor(&arrow);
  61.         }
  62.         else 
  63.             DisableItem (myMenus[editM], undoItem);
  64.     } /* else */
  65. } /*KillWindow*/
  66.         
  67.